from flask import request, jsonify
from . import app_login
from .login_notify import LoginNotify
from token_mmwl import Token




@app_login.route('/login', methods = ['POST', 'GET'])#登录api
def login_api():

    post_data, method = request.form, request.method#请求的参数，请求参数

    user, pass_word = post_data.get('user'), post_data.get('pass_word')#用户和密码

    login_notify_info = LoginNotify(user, pass_word, method).login_notify#测试登录和密码的返回值

    if login_notify_info['status'] == 1:#增加登陆token值

        company_id = login_notify_info["resultBody"]["user_info"]["id"]

        token = Token().insert_token(company_id)

        login_notify_info["resultBody"]['token'] = token#将获取的token值增加到返回值当中
    
    return jsonify(login_notify_info)

if __name__ == '__main__':
    
    app.run(debug = True)
    